﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Mod_FlatManger_frm_AddMenuItem : System.Web.UI.Page
{
    private void BindMenuType()
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst = cls_Menu.GetSysMenuTypes();

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            this.dropMenuType.Items.Clear();

            this.dropMenuType.DataTextField = "m_type_name";
            this.dropMenuType.DataValueField = "m_type_id";
            this.dropMenuType.DataSource = dst;
            this.dropMenuType.DataBind();
        }
        else
        {
            this.lblJs.Text = "<script>alert('获取系统菜单类别失败！');</script>";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            if (!IsPostBack)
            {
                this.BindMenuType();
            }
            else
            {
                this.lblJs.Text = "";
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>window.returnValue=-1;window.close();</script>";
        }
    }

    protected void btnServer_Click(object sender, EventArgs e)
    {
        ClsPropertyDAL cls_Property = new ClsPropertyDAL();

        string strUserID = cls_Property.SetOrGetUserID;

        if (strUserID != "")
        {
            int type = Int32.Parse(this.dropMenuType.SelectedItem.Value.Trim());
            int is_stop = (this.rbtnYes.Checked) ? 0 : 1;
            string strMenuName = this.txtMenuName.Text.Trim();
            string strMenuDesc = this.txtMenuDesc.Text.Trim();
            string strMenuUrl = this.txtMenuUrl.Text.Trim();

            ClsMenuDAL cls_Menu = new ClsMenuDAL();
            Boolean is_succeed = cls_Menu.AddMenuItem(type, strMenuName, strMenuDesc, strMenuUrl, is_stop, strUserID);

            if (is_succeed)
            {
                this.lblJs.Text = "<script>window.returnValue='True';window.close();</script>";
            }
            else
            {
                this.lblJs.Text = "<script>alert('新增系统菜单失败，请重试！');</script>"; 
            }
        }
        else
        {
            this.Page.Session.Remove("SetOrGetUserID");
            this.lblJs.Text = "<script>window.returnValue=-1;window.close();</script>";
        }
    }
}
